package huadi.concurrent.atomic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * Created with IntelliJ IDEA.
 *
 * @author zhufeng
 *         Date: 12-7-17
 *         Time: 下午6:09
 *         To change this template use File | Settings | File Templates.
 */
class Atomic2 implements AtomicCounter {
    private volatile int counter;
    private AtomicIntegerFieldUpdater<Atomic2> updater = AtomicIntegerFieldUpdater.newUpdater(Atomic2.class, "counter");

    public Atomic2(int c) {
        this.counter = c;
    }

    @Override
    public int get() {
        return updater.get(this);
    }

    @Override
    public void increment() {
        updater.addAndGet(this, 1);
    }
}
